package com.lxx.wiki.controller;

import com.lxx.wiki.domain.entity.Content;
import com.lxx.wiki.domain.req.ContentSaveReq;
import com.lxx.wiki.domain.req.DocSaveReq;
import com.lxx.wiki.domain.resp.CommonResp;
import com.lxx.wiki.domain.resp.ContentResp;
import com.lxx.wiki.service.ContentService;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/content")
public class ContentController {

    @Autowired
    private ContentService contentService;

    @GetMapping("/getById")
    public CommonResp getById(Long id) {
        ContentResp contentResp = contentService.getById(id);
        CommonResp<ContentResp> resp = new CommonResp<>();
        resp.setContent(contentResp);
        return resp;
    }

    /**
     * 新增或修改
     */
    @PostMapping("/save")
    public CommonResp save(@Valid @RequestBody ContentSaveReq contentSaveReq) {
        contentService.save(contentSaveReq);
        return new CommonResp<>();
    }
}
